package com.hanbang.maige.view.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.hanbang.maige.R;
import com.hanbang.maige.code.base.baseadapter.recyclerview.CommonAdapter;
import com.hanbang.maige.code.base.view.activity.BaseListActivity;
import com.hanbang.maige.code.base.view.iview.IListView;
import com.hanbang.maige.mode.javabean.home.NewsItemData;
import com.hanbang.maige.pressenter.home.NewsListPresenter;
import com.hanbang.maige.utils.ui.divider.HorizontalDividerItemDecoration;
import com.hanbang.maige.view.home.adapter.NewsAdapter;
import com.hanbang.maige.view.other.WebViewActivity;
import com.hanbang.maige.widget.empty_layout.ContextData;

import java.util.List;

/**
 * 作者　　: 李坤
 * 创建时间:2016/10/27　18:17
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class NewsListActivity extends BaseListActivity<IListView<NewsItemData>, NewsListPresenter, NewsItemData>
        implements IListView<NewsItemData> {
    public static void startUI(Context context) {
        Intent intent = new Intent(context, NewsListActivity.class);
        context.startActivity(intent);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_or_fragment_list;
    }

    @Override
    public void initView() {
        super.initView();
        toolbar.setBack(this);
        toolbar.setTitle("更多资讯");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        presenter.getHttpData(true);
    }

    @Override
    public RecyclerView.ItemDecoration getItemDecoration() {
        return new HorizontalDividerItemDecoration.Builder(this)
                .colorResId(R.color.black)
                .sizeResId(R.dimen.dp_1)
                .build()
                ;
    }

    @Override
    public CommonAdapter getAdapter() {
        return new NewsAdapter(this, listDatas);
    }

    @Override
    public void onRefresh() {
        presenter.getHttpData(true);
    }

    @Override
    public NewsListPresenter initPressenter() {
        return new NewsListPresenter();
    }


    @Override
    public void parseIntent(Intent intent) {

    }

    @Override
    public void onLoadding() {
        presenter.getHttpData(false);
    }

    @Override
    public void onRetryClick(ContextData data) {
        presenter.getHttpData(true);
    }

    @Override
    public void onEmptyClick(ContextData data) {
        presenter.getHttpData(true);
    }

    @Override
    public void upDataUI(List<NewsItemData> datas) {
        listDatas.addAll(datas);
        adapter.notifyDataSetChanged();
    }


    @Override
    public void clearData() {
        listDatas.clear();
    }

    @Override
    public void onItemClick(ViewGroup parent, View view, NewsItemData data, int position) {
        WebViewActivity.startUI(this, data.getTitle(), data.getUrl());
    }
}
